home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / fastbat.zip / FASTBAT.TXT
Text File  |  1988-02-16  |  4KB  |  106 lines

  1.                         SPEEDING UP BATCH FILES
  2.  
  3. Batch files make life a lot easier, but they are very slow.  Even when
  4. using batch files in RAM disks, execution time is quite noticeable.  It
  5. reminds me of the time when a batch file meant a batch of cards.  The
  6. techniques described here reduce the time required to execute batch
  7. file by as much as an order of magnitude.
  8.  
  9. Execution time is closely related to the number of lines rather than
  10. the number of characters.  To save time put as many commands on one
  11. line as possible.  Some ways to do this:
  12.  
  13. 1.  Instead of using a lot of lines for remarks, put what you have to
  14. say in a file and issue the batch command TYPE FILE.  TYPing a file
  15. takes less than 30% as long as echoing the same information from a
  16. batch file.
  17.  
  18. 2.  Instead of using a lot of lines to issue commands, put all the
  19. commands in a FOR subcommand.  For instance, your autoexec.bat file
  20. might start out
  21.                    fastdisk
  22.                    parint
  23.                    scrnsave
  24.                    spool 7    
  25.                    sk
  26.                    c:
  27.  
  28. Instead, just say
  29.  
  30.     for %%f in (fastdisk parint scrnsave spool:7 sk c:) do %%f
  31.  
  32. This reduces six lines to one.  In Dos 2.1, but not in 3.0, you can
  33. eliminate spaces and slightly decrease execution time like this:
  34.  
  35.     for %%fin(fastdisk parint scrnsave spool:7 sk c:)do%%f
  36.  
  37. Note the colon between spool and 7.  You can't have any spaces within
  38. the parentheses except to denote the beginning of a new command.
  39.  
  40. 3.  When copying files use the FOR subcommand and wild cards like this:
  41.  
  42.     for %%fin(print v sp)docopy a:%%f???.*
  43.  
  44. The FOR subcommand does not support wild cards within the parentheses.
  45.  
  46. How much time the FOR subcommand will save, if any, depends on how the
  47. remembers the entire subcommand.  It doesn't have to go back to disk to
  48. read more of the subcommand as it goes along.  But DOS doesn't remember
  49. the contents of the batch file unless it is held in disk buffers.
  50. Whether or not the disk buffers keep the contents of the batch file
  51. depends on what you're doing between batch commands.
  52.  
  53. 4.  The IF subcommand supports conditional commands and the FOR
  54. subcommand.
  55. For instance, you
  56. might want to see if a file exists and, if it does, to run several
  57. programs and then to return to the menu; or, if it doesn't to display a
  58. message and return to the menu.
  59. A batch file for this task might look like this:
  60.  
  61.          If exist myufile goto programs
  62.          echo File does not exist.  Try again.
  63.          d:menu
  64.          :programs
  65.          myprog.ram
  66.          second.prg
  67.          third
  68.          d:menu
  69.  
  70.     If exist myfile for %%fin(myprog.ram second.prg third d:menu)do%%f
  71.     for %%fin(echo d:menu)do%%f File does not exist.  Try again,
  72.  
  73. 5.  When a command processor is or another batch file is invoked, batch
  74. processing for the first batch is terminated.  You don't need to exit
  75. the batch file.  For example, in the batch file fragment below, the
  76. command GOTO GETOUT (and probably the label :GETOUT) is unnecessary and
  77. will increase execution time in some cases:
  78.             ..
  79.          command c:
  80.          goto to getout
  81.             ..
  82.             ..
  83.          :getout.
  84.  
  85. 6.  A fast way to get out of the middle of a batch file is to issue a
  86. command for another batch file, say a file called exit.  EXIT can contain
  87. only the command REM or just a dot or better yet nothing.  A file that
  88. contains nothing doesn't take up any disk space.  You can create such a
  89. file with another batch file, say autoexec.bat, by inserting this command
  90.  
  91.  
  92. The rem part of the command can be any command that doesn't look for
  93. parameters on the command line, e.g. cls or pause or sk.
  94.  
  95. 7.  Of course, running batch files from a RAM disk is a big help.  It's
  96. sometimes worth transferring control to a batch file that has been
  97. copied onto your RAM disk.  The time required for handling the batch
  98. operations in a RAM disk is less than a third of that required for a
  99. floppy.
  100.  
  101. 8.  Putting an end-of-file marker (ASCII 26 or Control Z) on the same
  102. line and immediately after the last command, will prevent annoying
  103. multiple prompts at the end of batch processing.
  104.  
  105. Bob Unferth                                           Wilmette, IL
  106.